from time import sleep
from selenium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver import ActionChains
from selenium.webdriver.common.actions import interaction
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.pointer_input import PointerInput


from basic.basedriver import DRIVER
from basic.basepage import BasePage


class PageAfterSalesService(BasePage):
    def installationServices_selectProductInstallation(self):
        self.click_by_text("安装服务")
        self.click_by_text("选择商品申请")
        clickTheProduct = AppiumBy.ANDROID_UIAUTOMATOR,"new UiSelector().className(\"android.widget.ImageView\").instance(2)"
        selectTheProduct = AppiumBy.ANDROID_UIAUTOMATOR,"new UiSelector().text(\"Redmi 智能电视 A32 节能版 黑色 32英寸\")"
        checkTheAgreement = AppiumBy.ANDROID_UIAUTOMATOR,"new UiSelector().className(\"android.widget.ImageView\").instance(7)"
        goToPay = AppiumBy.ANDROID_UIAUTOMATOR,"new UiSelector().text(\"去付款\")"
        self.click(clickTheProduct)
        self.click(selectTheProduct)
        self.click(checkTheAgreement)
        self.click(goToPay)
        sleep(1)
        return DRIVER.current_activity
    def installationServices_applyForAfterSales(self):
        self.click_by_text("申请售后")
        self.click_by_text("选择商品申请")
        clickTheProduct = AppiumBy.ANDROID_UIAUTOMATOR,'new UiSelector().className("android.widget.ImageView").instance(2)'
        selectTheProduct = AppiumBy.ANDROID_UIAUTOMATOR,'new UiSelector().text("Xiaomi 14 Ultra 16GB+1TB 龙晶蓝")'
        self.click(clickTheProduct)
        self.click(selectTheProduct)
        self.click_by_text("维修")
        self.click_by_text("电池故障")
        self.click_by_text("后盖破损")
        self.click_by_text("前置摄像头故障")
        self.click_by_text("后置摄像头故障")
        self.click_by_text("听筒故障")
        self.click_by_text("扬声器故障")
        self.click_by_text("其它故障")
        self.click_by_text("不开机或重启故障")
        self.click_by_text("屏幕故障")
        self.click_by_text("上门取件")
        self.click_by_text("预约到店")
        touch_input = PointerInput(interaction.POINTER_TOUCH, "touch")
        actions = ActionBuilder(DRIVER, mouse=touch_input)
        actions.pointer_action.move_to_location(709, 1809)  # 移动到起点
        actions.pointer_action.pointer_down()  # 按下
        actions.pointer_action.pause(0.2)  # 短暂停留，模拟真实触摸
        actions.pointer_action.move_to_location(698, 423)  # 滑动到终点
        actions.pointer_action.pause(0.1)  # 滑动过程中的停留
        actions.pointer_action.release()  # 释放
        actions.perform()
        sleep(1)
        self.click_by_text("请选择")
        self.click_by_text("确定")
        contact = DRIVER.find_element(AppiumBy.ANDROID_UIAUTOMATOR, "new UiSelector().text(\"请填写\").instance(0)")
        contactNumber = DRIVER.find_element(AppiumBy.ANDROID_UIAUTOMATOR,"new UiSelector().text(\"请填写\")")
        contact.click()
        contact.send_keys("张三")
        DRIVER.back()
        contactNumber.click()
        contact.send_keys("16642230165")
        return DRIVER.current_activity
    def product_collection(self):
        pass
    def shopping_cart(self):
        self.click_by_text("购物车")
        return DRIVER.current_activity
if __name__ == '__main__':
    result = PageAfterSalesService().installationServices_selectProductInstallation()
    print(result)
